package com.pb.wkflow.api.controller.assembler.mapper;

import com.pb.infra.oth.util.UserInfo;
import com.pb.wkflow.api.controller.request.ClassifyQueryRequest;
import com.pb.wkflow.api.entity.WfSysClassifyEntity;
import com.pb.wkflow.core.utils.DateUtils;
import com.pb.wkflow.core.utils.SnowFlake;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;

import java.util.Date;

/**
 * DTO 转换
 * @author 苗益辉
 * @date 2022/12/27 10:00
 */
@Mapper(imports = {SnowFlake.class, DateUtils.class, Date.class})
public interface ClassifyDtoMapper {

    ClassifyDtoMapper INSTANCE = Mappers.getMapper(ClassifyDtoMapper.class);

    /**
     * WfSysClassifyEntity DTO 转换
     * @param request request
     * @param userInfo userInfo
     * @return WfSysClassifyEntity
     */
    @Mapping(target = "classifyName", source = "request.classifyName")
    @Mapping(target = "updateTime", source = "request.updateTime")
    @Mapping(target = "isAble", source = "request.isAble")
    @Mapping(target = "tenantId", source = "userInfo.corpId")
    WfSysClassifyEntity assemblerToQuery(ClassifyQueryRequest request, UserInfo userInfo);

    /**
     * assemblerToSave
     * @param request request
     * @param userInfo userInfo
     * @return WfSysClassifyEntity
     */
    @Mapping(target = "id", expression = "java(SnowFlake.nextId())")
    @Mapping(target = "classifyCode", source = "request.classifyCode")
    @Mapping(target = "classifyName", source = "request.classifyName")
    @Mapping(target = "tenantId", source = "userInfo.corpId")
    @Mapping(target = "createTime", expression = "java(DateUtils.dateToStr(new Date()))")
    @Mapping(target = "updateTime", expression = "java(DateUtils.dateToStr(new Date()))")
    WfSysClassifyEntity assemblerToSave(ClassifyQueryRequest request, UserInfo userInfo);

    /**
     * assemblerToUpdate
     * @param request request
     * @param entity entity
     */
    @Mapping(target = "classifyCode", source = "classifyCode")
    @Mapping(target = "classifyName", source = "classifyName")
    @Mapping(target = "isAble", source = "isAble")
    @Mapping(target = "updateTime", expression = "java(DateUtils.dateToStr(new Date()))")
    void assemblerToUpdate(ClassifyQueryRequest request, @MappingTarget WfSysClassifyEntity entity);
}
